<template>
  <a-spin class="card_info_content card_info_container" :spinning="loading">
    <div class="card_info_wrapper">
      <div class="title_wrapper">
        <div class="title_left_wrapper">
          <span class="title_text">今日平均得分</span>
          <span class="title_value">{{ typeof (cardData.avgScore) == 'number' ? cardData.avgScore.toFixed(2) : 0 }}</span>
        </div>
        <img src="@/assets/dataValidate/home_card_icon1.png" class="title_icon">
      </div>
      <div class="trend_wrapper">
        <div class="trend_left_wrapper">
          <div :class="[cardData.scoreIncrease > 0 ? 'trend_up' : 'trend_down', 'trend_normal']">
            <img
              :src="cardData.scoreIncrease > 0
                ? require('@/assets/dataValidate/home_card_up.png')
                : require('@/assets/dataValidate/home_card_down.png')"
              class="trend_icon">
            <span class="trend_value">{{ cardData.scoreIncrease ? (cardData.scoreIncrease*100).toFixed(2) : 0 }}%</span>
          </div>
          <span class="trend_text">环比昨日</span>
        </div>
        <img
          :src="cardData.scoreIncrease > 0
            ? require('@/assets/dataValidate/home_card_up2.png')
            : require('@/assets/dataValidate/home_card_down2.png')"
          class="trend_chart">
      </div>
    </div>
    <div class="card_info_wrapper">
      <div class="title_wrapper">
        <div class="title_left_wrapper">
          <span class="title_text">数据总数</span>
          <span class="title_value">{{ cardData.dataCount ? cardData.dataCount : 0 }}</span>
        </div>
        <img src="@/assets/dataValidate/home_card_icon2.png" class="title_icon">
      </div>
      <div class="trend_wrapper">
        <div class="trend_left_wrapper">
          <div :class="[cardData.countIncrease > 0 ? 'trend_up' : 'trend_down', 'trend_normal']">
            <img
              :src="cardData.countIncrease > 0
                ? require('@/assets/dataValidate/home_card_up.png')
                : require('@/assets/dataValidate/home_card_down.png')"
              class="trend_icon">
            <span class="trend_value">{{ cardData.countIncrease ? (cardData.countIncrease*100).toFixed(2) : 0 }}%</span>
          </div>
          <span class="trend_text">环比昨日</span>
        </div>
        <img
          :src="cardData.countIncrease > 0
            ? require('@/assets/dataValidate/home_card_up2.png')
            : require('@/assets/dataValidate/home_card_down2.png')"
          class="trend_chart">
      </div>
    </div>
    <div class="card_info_wrapper">
      <div class="title_wrapper">
        <div class="title_left_wrapper">
          <span class="title_text">异常总数</span>
          <span class="title_value">{{ cardData.errorCount ? cardData.errorCount : 0 }}</span>
        </div>
        <img src="@/assets/dataValidate/home_card_icon3.png" class="title_icon">
      </div>
      <div class="trend_wrapper">
        <div class="trend_left_wrapper">
          <div :class="[cardData.errorCountIncrease > 0 ? 'trend_down' : 'trend_up', 'trend_normal']">
            <img
              :src="cardData.errorCountIncrease > 0
                ? require('@/assets/dataValidate/home_card_up.png')
                : require('@/assets/dataValidate/home_card_down.png')"
              class="trend_icon">
            <span class="trend_value">{{ cardData.errorCountIncrease ? (cardData.errorCountIncrease*100).toFixed(2) : 0 }}%</span>
          </div>
          <span class="trend_text">环比昨日</span>
        </div>
        <img
          :src="cardData.errorCountIncrease > 0
            ? require('@/assets/dataValidate/home_card_down2.png')
            : require('@/assets/dataValidate/home_card_up2.png')"
          class="trend_chart">
      </div>
    </div>
    <div class="card_info_wrapper">
      <div class="title_wrapper">
        <div class="title_left_wrapper">
          <span class="title_text">异常比例</span>
          <span class="title_value">{{ cardData.errorRatio ? (cardData.errorRatio*100).toFixed(2) : 0 }}%</span>
        </div>
        <img src="@/assets/dataValidate/home_card_icon4.png" class="title_icon">
      </div>
      <div class="trend_wrapper">
        <div class="trend_left_wrapper">
          <div :class="[cardData.errorRatioIncrease > 0 ? 'trend_down' : 'trend_up', 'trend_normal']">
            <img
              :src="cardData.errorRatioIncrease > 0
                ? require('@/assets/dataValidate/home_card_up.png')
                : require('@/assets/dataValidate/home_card_down.png')"
              class="trend_icon">
            <span class="trend_value">{{ cardData.errorRatioIncrease ? (cardData.errorRatioIncrease*100).toFixed(2) : 0 }}%</span>
          </div>
          <span class="trend_text">环比昨日</span>
        </div>
        <img
          :src="cardData.errorRatioIncrease > 0
            ? require('@/assets/dataValidate/home_card_down2.png')
            : require('@/assets/dataValidate/home_card_up2.png')"
          class="trend_chart">
      </div>
    </div>
  </a-spin>
</template>

<script>
import { banner } from '@/api/home'
export default {
  props: {},
  data () {
    return {
      loading: false,
      cardData: {
        avgScore: 0,
        countIncrease: 0,
        dataCount: 0,
        errorCount: 0,
        errorCountIncrease: 0,
        errorRatio: 0,
        errorRatioIncrease: 0,
        scoreIncrease: 0,
        yesterdayAvgScore: 0,
        yesterdayDataCount: 0,
        yesterdayErrorCount: 0,
        yesterdayErrorRatio: 0
      }
    }
  },
  components: {},
  computed: {},
  watch: {},
  methods: {
    requestBannerData () {
      this.loading = true
      banner({
        now: ''
      }).then((res) => {
        console.log(res)
        if (res.code === 200 && res.data) {
          this.cardData = res.data
          console.log(typeof (this.cardData.avgScore))
        }
      }).catch((err) => {
        console.log(err)
      }).finally(() => {
        this.loading = false
      })
    }
  },
  created () {
    this.requestBannerData()
  },
  beforeMount () {},
  mounted () {},
  activated () {}
}
</script>

<style scoped lang="less">
.card_info_content{
  width: 100%;
  .card_info_wrapper{
    width:24.055%;
    height:140px;
    background:rgba(255,255,255,1);
    box-shadow:0px 3px 10px 0px rgba(96,122,151,0.13);
    border-radius:4px;
    padding: 0 28px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .title_wrapper{
    display: flex;
    align-items: center;
  }
  .title_left_wrapper{
    flex: 1;
    display: flex;
    flex-direction: column;
  }
  .title_text{
    font-size:14px;
    font-weight:400;
    color:rgba(101,101,101,1);
  }
  .title_value{
    font-size:18px;
    font-weight:bold;
    color:rgba(51,51,51,1);
  }
  .title_icon{
    width: 50px;
    height: 50px;
  }

  .trend_left_wrapper{
    display: flex;
    align-items: center;
  }
  .trend_wrapper{
    margin-top: 12px;
    display: flex;
  }
  .trend_normal{
    width:68px;
    height:26px;
    border-radius:13px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .trend_up{
    background:rgba(21,199,119,1);
  }
  .trend_down{
    background:rgba(247,100,90,1);
  }
  .trend_icon{
    width: 10px;
    height: 11px;
  }
  .trend_value{
    font-size:12px;
    font-weight:400;
    color:rgba(255,255,255,1);
    margin-left: 4px;
  }
  .trend_text{
    font-size:12px;
    font-weight:400;
    color:rgba(153,153,153,1);
    margin-left: 10px;
  }
  .trend_chart{
    margin-left: 30px;
    width: 115px;
    height: 41px;
  }
}
</style>
<style lang="less">
.card_info_container{
  .ant-spin-container{
    display: flex;
    justify-content: space-between;
    flex-wrap: nowrap;
  }
}
</style>
